 <!--
* description: 其它出库审核
* author: chenjingwen
* createdDate: 2021-3-4
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-table-cols="tableCols"
      :dynamic-api-config="apiConfig"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="true"
      :dynamic-is-show-more-btn="true"
      :callback-obj="callbackObj"
    />

    <Edit
      :is-view-pop-windows="isViewPopWindows"
      :dynamic-edit-row-data="editRowData"
      @close="close"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import api from '@/api/subsidyManage'
import Vue from 'vue'
import { vehiclePdiPriceInquirys } from '@/api/se/vehiclePdiPriceInquiry'
import { exportExcel } from '@/utils/getTimeString.js'

export default {
  name: 'Otherdeliveryaudit',

  components: {
    OneTableTemplate,
    Edit: () => import('./edit')
  },

  // 组件混入对象：{data[listQuery] methods[queryTable]}
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ''], function() {
      next()
    })
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])

    return {
      // 网格查询API配置对象
      apiConfig: vehiclePdiPriceInquirys.queryOtherOutboundAuditInfo,
      editRowData: {},
      selectData: {},
      editPopupsVisible: false,

      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey3',
          type: 'primary',
          size: 'small',
          name: 'search',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'), // 查询
          position: 'right',
          fuzzySearch: true
        },

        {
          compKey: 'btnKey3',
          type: 'primary',
          size: 'small',
          name: '',
          clickEvent: () => this.pass(),
          text: '批量审核', // 批量审核
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey3',
          type: 'primary',
          size: 'small',
          name: '',
          clickEvent: () => this.reject(),
          text: '批量驳回', // 批量驳回
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey3',
          type: 'primary',
          size: 'small',
          name: 'export',
          clickEvent: () => this.exportExcel111(),
          text: this.$t('sys.button.export'), // 导出
          position: 'right',
          fuzzySearch: true
        }
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            {
              compKey: 'compKey1',
              labelName: '申请单号:',
              codeField: 'applyOrderCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: false,
              isMul: false,
              isMust: true
            },
            {
              compKey: 'key8',
              labelName: '出库类型:',
              codeField: 'outboundType',
              component: () => import('@/components/org/LookupValue'),
              oFields: 'statusId,statusText',
              type: 'dropdownList',
              options: [
                { statusId: '4', statusText: '领用出库' },
                { statusId: '6', statusText: '报废出库' }
              ],
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: '领用去向:',
              codeField: 'applyDept',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: '申请人:',
              codeField: 'applyPerson',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',

              isMul: false,
              isMust: true
            },
            {
              compKey: 'key8',
              labelName: '申请日期:',
              codeField: 'beginDate,endDate',
              component: () =>
                import('@/components/org/datePicker/andtDatePicker'),
              type: 'YYYY-MM-DD',
              format: 'yyyy-MM-dd',
              isMul: false,
              isMust: false
            },
            {
              compKey: 'compKey4',
              labelName: '领用仓库:',
              codeField: 'warehouseName',
              component: () => import('@/components/org/commonSelect'),
              oFields: 'warehouseName,warehouseName',
              customObj: {
                api: {
                  APIUrl: '/mp/e3sh/spareparts/nodestorehouse/checkWarehousingService/queryWarehouseName.do'
                }
              },
              isMul: false,
              isMust: false
            },
            {
              compKey: 'compKey5',
              labelName: '成本中心:',
              codeField: 'costCentre',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',

              isMul: false,
              isMust: false
            },
            {
              compKey: 'key11',
              labelName: '审核状态:',
              codeField: 'applyStatus',
              component: () => import('@/components/org/LookupValue'),
              oFields: 'statusId,statusText',
              type: 'dropdownList',
              options: [
                { statusId: '0', statusText: '待审核' },
                { statusId: '1', statusText: '审核通过' },
                { statusId: '2', statusText: '已退回' },
                { statusId: '3', statusText: '作废' }
              ],
              isMul: false,
              isMust: false
            }
          ],
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'subsidyId',
              label: '主键ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'updateControlId',
              label: '并发控制ID',
              hidden: true,
              alwaysHidden: true
            },

            {
              prop: 'applyOrderCode',
              label: '申请单号',
              isComponent: true,
              comps: [
                {
                  compKey: 'propKey1',
                  codeField: 'applyOrderCode',
                  component: () => import('@/components/org/linkButton'),
                  clickEvent: (index) => {
                    this.isViewPopWindows = true
                    this.editRowData = this.$utils.deepCopy(
                      this.$refs['multipleTable'].list[index]
                    )
                  }
                }
              ]
            },

            {
              prop: 'applyDate',
              label: '申请日期'
            },
            {
              prop: 'warehouseName',
              label: '领用仓库'
            },
            {
              prop: 'outboundTypeCn',
              label: '出库类型'
            },
            {
              prop: 'applyDept',
              label: '领用去向'
            },
            {
              prop: 'costCentre',
              label: '成本中心'
            },
            {
              prop: 'applyPerson',
              label: '申请人'
            },
            {
              prop: 'partSpecies',
              label: '品种数'
            },

            {
              prop: 'applyUse',
              label: '出库用途'
            },
            {
              prop: 'receivePerson',
              label: '收货人'
            },
            {
              prop: 'linkPhone',
              label: '联系电话'
            },
            {
              prop: 'receiveAddress',
              label: '收货地址'
            },
            {
              prop: 'applyStatusCn',
              label: '审核状态'
            }
          ],
      selectiondata: [],
      // 回调方法对象
      callbackObj: {
        // 网格点击回调事件
        onRowClick: (currentRow) => {
          // this.onRightRowClick(currentRow);
        },
        // 手动勾选网格时，拿到勾选网格的数据
        onCheckSelect: (selection, row) => {
          this.selectiondata = selection
        },
        onCheckSelectChange: (selection) => {
          // this.onCheckSelectChange1(selection)
        }
      },

      // 表单数据
      formField: this.$utils.getFormField(
        this,
        {
          applyOrderCode: '',
          outboundType: '',
          applyDept: '',
          applyPerson: '',
          applyDate: '',
          warehouseName: '',
          costCentre: '',
          applyStatus: '',
          beginDate: '',
          endDate: ''
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      )
    }
  },

  mounted() {
    // 列表查询
    this.queryTable(1)
  },

  methods: {
    edit(index) {
      this.editPopupsState = 'edit'
      this.editPopupsVisible = true
      this.editRowData = this.$refs['multipleTable'].list[index]
    },
    close() {
      this.editPopupsVisible = false
      this.queryTable(1)
    },
    pass() {
      if (!this.selectiondata || this.selectiondata.length == 0) {
        this.$message({
          message: '请至少选择一条数据',
          type: 'warn',
          duration: 2000
        })
        return
      }
      const that = this
      const queryObj = {
        // 保存mutation
        type: 'mutation',
        // api配置
        apiConfig: vehiclePdiPriceInquirys.auditPass,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: this.selectiondata
      }
      // 转换了中台请求格式数据
      var paramD = that.$getParams(queryObj)
      // 调用中台API方法（可复用）
      that.$requestAPI(paramD).then((response) => {
        if (response.result === '1') {
          this.$message({
            message: '已通过',
            type: 'success',
            duration: 2000
          })
          // this.open()
          // this.isViewPopWindows = false
          this.$refs['multipleTable'].queryTable()
        } else {
          // 保存失败
          this.$message({
            message: response.msg || '保存失败',
            type: 'warn',
            duration: 2000
          })
        }
      })
    },
    // 驳回
    reject() {
      if (!this.selectiondata || this.selectiondata.length == 0) {
        this.$message({
          message: '请至少选择一条数据',
          type: 'warn',
          uration: 2000
        })
        return
      }
      const that = this
      const queryObj = {
        // 保存mutation
        type: 'mutation',
        // api配置
        apiConfig: vehiclePdiPriceInquirys.auditReject,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: this.selectiondata
      }
      // 转换了中台请求格式数据
      var paramD = that.$getParams(queryObj)
      // 调用中台API方法（可复用）
      that.$requestAPI(paramD).then((response) => {
        if (response.result === '1') {
          this.$message({
            message: '已驳回',
            type: 'success',
            duration: 2000
          })
          this.$refs['multipleTable'].queryTable()
        } else {
          // 保存失败
          this.$message({
            message: response.msg || '保存失败',
            type: 'warn',
            duration: 2000
          })
        }
      })
    },
    exportExcel111() {
      exportExcel(
        this.formField,
        vehiclePdiPriceInquirys.exportDetails2.APIUrl,
        vehiclePdiPriceInquirys.exportDetails2.ServiceCode,
        '其它出库审核'
      )
    }
  }
}
</script>
